<template>
<div>
  <!-- 编辑条件 -->
  <el-dialog :visible.sync="isShow" v-if="isShow" title="条件机器人" width="60%" :before-close="handleClose" top="50px" :close-on-click-modal="false">
    <div v-if="condition" class="border-box" style="height: 70vh;overflow: auto;">
      <el-tree :data="conditionDataList" show-checkbox node-key="id" ref="tree" @check="chooseCondition" />
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="medium" @click="handleClose">取 消</el-button>
      <el-button v-if="condition" :disabled="chooseDataList.length>0?false:true" type="warning" size="medium" @click="editCondition">编 辑</el-button>
    </span>
  </el-dialog>
  <!-- 新增编辑 -->
  <el-dialog :append-to-body="true" :visible.sync="editShow" v-if="editShow" title="机器人条件" width="58%" :before-close="conditionClose" top="50px" :close-on-click-modal="false">
    <!-- <div class="border-box" style="height: 70vh;overflow: auto;"> -->
    <div class="border-box">
      <el-form ref="conditionForm" :model="formParams" :rules="conditionForm" label-position="right" label-width="0">
        <!-- 配置 -->
        <div v-for="(item,index) in chooseDataList" :key="index">
          <p v-if="condition" class="box-title">ID:【<span class="colorRed">{{ item.id }}</span>】 行为：<span class="colorRed">{{ item.label }}</span></p>
          <!-- 表单 -->
          <div class="flex item-box" v-for="(third,three) in itemData" :key="three">
            <div class="title width25">
              {{ third.label }}
            </div>
            <div class="content width80">
              <el-form-item class="item-clear" v-show="third.key=='robot_id'">
                <el-input-number :min="1" :max="999999999" :precision="0" v-model="formParams.robot_condition_id" controls-position="right" clearable placeholder="请输入机器人条件ID"/>
              </el-form-item>
              <el-form-item class="item-clear" v-show="third.key=='robot'" v-if="!condition" label="">
                <el-select v-model="item.a_base_robot_id" placeholder="请选择机器人" filterable>
                  <el-option :label="second.a_robot_remark" :value="second.a_base_robot_id" v-for="(second,two) in robotDataList" :key="two"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item class="item-clear" v-show="third.key=='remark'" label="">
                <el-input type="text" v-model="item.a_robot_remark" clearable placeholder="请输入备注"></el-input>
              </el-form-item>
              <el-form-item class="item-clear" v-show="third.key=='trigger'" label="">
                <div class="flex" v-for="(second,two) in item.a_robot_trigger" :key="two">
                  <el-select class="width200"  v-model="second.type" placeholder="请选择行为触发点" filterable >
                    <el-option :label="fourthly.label" :value="fourthly.value" v-for="(fourthly,four) in triggerData" :key="four"></el-option>
                  </el-select>
                  —
                  <el-input-number :min="1" :max="999999999" :precision="0" v-model="second.condition" controls-position="right" clearable placeholder="请输入延迟时间max"/>
                </div>
              </el-form-item>
              <el-form-item  class="item-clear" v-show="third.key=='delay'" label="">
                <div class="flex" v-for="(second,two) in item.a_robot_delay" :key="two">
                  <el-input-number :min="0" :max="999999999" :precision="0" v-model="second.type" controls-position="right" clearable placeholder="请输入延迟时间min"/>
                  —
                  <el-input-number :min="1" :max="999999999" :precision="0" v-model="second.condition" controls-position="right" clearable placeholder="请输入延迟时间max"/>
                </div>
              </el-form-item>
              <!-- 机器人充值次数概率 -->
              <div v-show="third.key=='recharge'" class="paddingT20">
                <div class="flex" v-for="(second,two) in item.recharge_num_rand" :key="two" style="height:50px">
                  <div class="btn-box-add">
                    <el-button v-show="rechargeIndex==two" class="marginL10" size="mini" type="primary" circle icon="el-icon-plus" @click="addRecharge(index)" />
                  </div>
                  <el-form-item label="次数:" label-width="70px">
                    <el-input-number :min="0" :max="999999999" :precision="0" v-model="second.type" controls-position="right" clearable placeholder="请输入充值次数"/>
                  </el-form-item>
                  <el-form-item label="概率:" label-width="60px">
                    <el-input-number :min="0" :max="10000" :precision="0" v-model="second.condition" controls-position="right" clearable placeholder="请输入充值概率"/>
                  </el-form-item>
                  <div class="btn-box-delete">
                    <el-button v-show="item.recharge_num_rand.length != 1" class="marginL10" size="mini" type="danger" circle icon="el-icon-minus" @click="deleteRecharge(index,two)" />
                  </div>
                </div>
              </div>
              <!-- 局内筹码不足是否充值 -->
              <div v-show="third.key=='recharge_rand'" class="paddingT20">
                <div class="flex" v-for="(second,two) in item.is_recharge_rand" :key="two" style="height:50px">
                  <div class="btn-box-add">
                    <el-button v-show="rechargeRandIndex==two" class="marginL10" size="mini" type="primary" circle icon="el-icon-plus" @click="addRechargeRand(index)" />
                  </div>
                  <el-form-item label="充值档位:" label-width="90px">
                    <el-select class="width200" v-model="second.type" placeholder="请选择行为触发点" filterable>
                      <el-option :label="fourthly.label" :value="fourthly.value" v-for="(fourthly,four) in rechargeData" :key="four"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="概率:" label-width="60px">
                    <el-input-number :min="0" :max="10000" :precision="0" v-model="second.condition" controls-position="right" clearable placeholder="请输入充值概率"/>
                  </el-form-item>
                  <div class="btn-box-delete">
                    <el-button v-show="item.is_recharge_rand.length != 1" class="marginL10" size="mini" type="danger" circle icon="el-icon-minus" @click="deleteRechargeRand(index,two)" />
                  </div>
                </div>
              </div>
              <!-- 充值额度权限 -->
              <el-form-item class="item-clear" v-show="third.key=='credit_rand'" label="">
                <el-input-number :min="0" :max="999999999" :precision="0" v-model="item.recharge_credit_rand" controls-position="right" clearable placeholder="请输入不同充值额度权重"/>
              </el-form-item>
              <!-- 机器人充值随机时间 -->
              <div v-show="third.key=='recharge_time'" class="paddingT20">
                <div class="flex" v-for="(second,two) in item.recharge_time_rand" :key="two" style="height:50px">
                  <div class="btn-box-add">
                    <el-button v-show="rechargeTimeIndex==two" class="marginL10" size="mini" type="primary" circle icon="el-icon-plus" @click="addRechargeTime(index)" />
                  </div>
                  <el-form-item label="时间(秒):" label-width="90px">
                    <el-input-number :min="0" :max="999999999" :precision="0" v-model="second.type" controls-position="right" clearable placeholder="请输入充值次数"/>
                  </el-form-item>
                  <el-form-item label="概率:" label-width="60px">
                    <el-input-number :min="0" :max="10000" :precision="0" v-model="second.condition" controls-position="right" clearable placeholder="请输入充值概率"/>
                  </el-form-item>
                  <div class="btn-box-delete">
                    <el-button v-show="item.recharge_time_rand.length != 1" class="marginL10" size="mini" type="danger" circle icon="el-icon-minus" @click="deleteRechargeTime(index,two)" />
                  </div>
                </div>
              </div>
              <!-- 机器人离开房间随机时间 -->
              <div v-show="third.key=='exit_time'" class="paddingT20">
                <div class="flex" v-for="(second,two) in item.exit_time_rand" :key="two" style="height:50px">
                  <div class="btn-box-add">
                    <el-button v-show="exitTimeIndex==two" class="marginL10" size="mini" type="primary" circle icon="el-icon-plus" @click="addExitTime(index)" />
                  </div>
                  <el-form-item label="时间(秒):" label-width="90px">
                    <el-input-number :min="0" :max="999999999" :precision="0" v-model="second.type" controls-position="right" clearable placeholder="请输入充值次数"  />
                  </el-form-item>
                  <el-form-item label="概率:" label-width="60px">
                    <el-input-number :min="0" :max="10000" :precision="0" v-model="second.condition" controls-position="right" clearable placeholder="请输入充值概率"  />
                  </el-form-item>
                  <div class="btn-box-delete">
                    <el-button v-show="item.exit_time_rand.length != 1" class="marginL10" size="mini" type="danger" circle icon="el-icon-minus" @click="deleteExitTime(index,two)" />
                  </div>
                </div>
              </div>
              <!-- 机器人行为 -->
              <div v-show="third.key=='condition'" class="paddingT20">
                <div class="flex" v-for="(second,two) in item.a_robot_condition" :key="two" style="height:50px">
                  <div class="btn-box-add">
                    <el-button v-show="conditionIndex==two" class="marginL10" size="mini" type="primary" circle icon="el-icon-plus" @click="addCondition(index)" />
                  </div>
                  <el-form-item label="条件:" label-width="70px">
                    <el-select v-model="second.type" placeholder="请选择条件" filterable>
                      <el-option :label="fourthly.label" :value="fourthly.value" v-for="(fourthly,four) in ROBOT_CONDITION" :key="four"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="万分比:" v-if="second.type==4" label-width="80px">
                    <el-input-number :min="0" :max="999999999" :precision="0" v-model="second.min" controls-position="right" clearable placeholder="请输入牌组类型min" style="width: 150px;" />
                    —
                    <el-input-number :min="1" :max="999999999" :precision="0" v-model="second.max" controls-position="right" clearable placeholder="请输入牌组类型max" style="width: 150px;" />
                  </el-form-item>
                  <el-form-item label="参数:" v-if="second.type!=4" label-width="60px">
                    <el-input-number :min="0" :max="999999999" :precision="0" v-model="second.condition" controls-position="right" clearable placeholder="请输入参数"  />
                  </el-form-item>
                  <div class="btn-box-delete" >
                    <el-button  v-show="item.a_robot_condition.length != 1" class="marginL10" size="mini" type="danger" circle icon="el-icon-minus" @click="deleteCondition(index,two)" />
                  </div>
                </div>
              </div>
              <!-- 行为触发条件 -->
              <div v-show="third.key=='behavior'" class="paddingT20">
                <div class="flex" v-for="(second,two) in item.a_robot_behavior" :key="two" style="height:50px">
                  <div class="btn-box-add">
                    <el-button v-show="behaviorIndex==two" class="marginL10" size="mini" type="primary" circle icon="el-icon-plus" @click="addBehavior(index)" />
                  </div>
                  <el-form-item label="行为:" label-width="70px">
                    <el-select v-model="second.action" placeholder="请选择行为" filterable>
                      <el-option :label="fourthly.label" :value="fourthly.value" v-for="(fourthly,four) in ROBOT_BEHAVIOR" :key="four"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="参数:" label-width="60px">
                    <el-input-number :min="0" :max="999999999" :precision="0" v-model="second.pro" controls-position="right" clearable placeholder="请输入参数"  />
                  </el-form-item>
                  <div class="btn-box-delete">
                    <el-button v-show="item.a_robot_behavior.length != 1" class="marginL10" size="mini" type="danger" circle icon="el-icon-minus" @click="deleteBehavior(index,two)" />
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="medium" @click="conditionClose">取 消</el-button>
      <el-button size="medium" type="primary" @click="handleConfirm('conditionForm')">确 定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
import {
  allRobot,
  editRobotCondition,
  addRobotCondition
} from "@/api/game";
import {
  ROBOT_BEHAVIOR,
  ROBOT_CONDITION,
} from "@/utils/enum";

export default {
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    addShow: {
      type: Boolean,
      default: false
    },
    condition: {
      type: Array,
      default: function () {
        return []
      }
    },
    robotType: {
      type: Number,
      default: 1
    },
  },
  data () {
    return {
      ROBOT_BEHAVIOR,
      ROBOT_CONDITION,
      isShow: false,
      behaviorIndex: 0,
      conditionIndex: 0,
      rechargeIndex: 0,
      rechargeRandIndex: 0,
      rechargeTimeIndex: 0,
      exitTimeIndex: 0,
      formParams: {},
      editShow: false,
      itemData:[
        { label: '机器人条件ID', key: 'robot_id' },
        { label: '机器人', key: 'robot' },
        { label: '备注', key: 'remark' },
        { label: '触发点', key: 'trigger' },
        { label: '延迟时间', key: 'delay' },
        { label: '机器人充值次数', key: 'recharge' },
        { label: '局内筹码不足是否充值', key: 'recharge_rand' },
        { label: '不同充值额度权重', key: 'credit_rand' },
        { label: '机器人充值随机时间', key: 'recharge_time' },
        { label: '机器人离开房间随机时间', key: 'exit_time' },
        { label: '机器人行为', key: 'condition' },
        { label: '行为触发条件', key: 'behavior' },
      ],
      conditionDataList: [{
        game_id: this.robotType,
        robot_condition_id: '', //机器人条件id
        a_base_robot_id: '', //机器人id
        a_robot_remark: '', //机器人备注
        a_robot_condition: [{ //条件参数
          type: 1,
          condition: '',
          min: '',
          max: '',
        }],
        a_robot_trigger: [{ //触发点
          type: 1,
          condition: '',
        }], 
        a_robot_behavior: [{ //行为
          action: 1,
          pro: '',
        }],
        a_robot_delay:[{ //延迟时间
          type: 1,
          condition: '',
        }],
        recharge_num_rand:[{ //机器人充值次数
          type: 1, 
          condition: 1
        }],
        is_recharge_rand:[{ //局内筹码不足机器人充值及金额
          type: 1, 
          condition: 1
        }],
        recharge_credit_rand: '', // 充值额度权限
        recharge_time_rand:[{ // 机器人充值随机时间
          type: 1, 
          condition: 1
        }],
        exit_time_rand:[{ // 机器人离开房间随机时间
          type: 1, 
          condition: 1
        }],
      }],
      triggerData:[
        { label: '回合开始', value: 1 },
        { label: '别人回合开始', value: 2 },
        { label: '回合结束', value: 3 },
        { label: '看牌', value: 4 },
        { label: '弃牌', value: 5 },
        { label: '翻倍', value: 6 },
        { label: '押注', value: 7 },
        { label: '被比牌', value: 8 },
        { label: '轮次调整', value: 9 },
        { label: '抽牌', value: 10 },
        { label: '对局结束', value: 11 },
        { label: '亮牌', value: 12 },
        { label: '别人回合经过时间', value: 13 },
        { label: '不看牌', value: 14 },
      ],
      rechargeData:[
        { label: '充值档位一', value: 1 },
        { label: '充值档位二', value: 2 },
        { label: '充值档位三', value: 3 },
        { label: '充值档位四', value: 4 },
        { label: '充值档位五', value: 5 },
      ],
      chooseDataList: [],
      robotDataList: [],
      conditionForm: {},
    }
  },
  computed: {},
  watch: {
    show: function () {
      let that = this;
      that.isShow = that.show
      that.chooseDataList=[]
    },
    addShow: function () {
      let that = this;
      that.editShow = that.addShow
      that.chooseDataList = [{
          game_id: this.robotType,
          robot_condition_id: '',
          a_base_robot_id: '', //机器人id
          a_robot_remark: '', //机器人备注
          a_robot_condition: [{ //条件参数
            type: 1,
            condition: '',
            min: '',
            max: '',
          }],
          a_robot_trigger: [{ //触发点
            type: 1,
            condition: '',
          }], 
          a_robot_behavior: [{ //行为
            action: 1,
            pro: '',
          }],
          a_robot_delay:[{ //延迟时间
            type: 1,
            condition: '',
          }],
          recharge_num_rand:[{ //机器人充值次数
            type: 1, 
            condition: 1
          }],
          is_recharge_rand:[{ //局内筹码不足机器人充值及金额
            type: 1, 
            condition: 1
          }],
          recharge_credit_rand: '', // 充值额度权重
          recharge_time_rand:[{ // 机器人充值随机时间
            type: 1, 
            condition: 1
          }],
          exit_time_rand:[{ // 机器人离开房间随机时间
            type: 1, 
            condition: 1
          }],
        }];
        that.editCondition()
    },
    condition: function () {
      let that = this, action = '', conditionData = [];
      that.conditionDataList = []
      if (that.condition) {
        that.condition.map((item, index) => {
          let childrenSecond = [], childrenThird = [];
          // 三级展示            
          item.children.children.map(third => {
            childrenThird.push({
              id: third.id,
              label: third.a_robot_remark,
              a_base_robot_id: third.a_base_robot_id,
              a_robot_behavior: JSON.parse(third.a_robot_behavior),
              a_robot_condition: third.a_robot_condition,
              a_robot_delay: third.a_robot_delay,
              a_robot_remark: third.a_robot_remark,
              a_robot_trigger: third.a_robot_trigger,
              game_id: third.game_id,
              operated_id: third.operated_id,
            })
          })
          // 二级行为
          item.children.map(second => {
            action += that.actionType(second.action) + '(' + second.pro + ')-'
            childrenSecond.push({
              id: Number(item.id) + 1,
              label: action,
              children: childrenThird
            })
          })
          conditionData.push({
            id: Number(item.id),
            label: '机器人ID:' + item.id,
            children: childrenSecond
          })
        })
        conditionData.map((item, index) => {
          item.children.splice(0, item.children.length - 1,)
          item.children.map(second => {
            second.id = second.id + index
            that.conditionDataList.push(second)
          })
        })
      }
    }
  },
  mounted () {
    this.getAllRobot()
  },
  methods: {
    // 查询所有机器人
    getAllRobot(){
      let that=this;
      allRobot({}).then(function (res) {
        if (res.data) {
          that.robotDataList = res.data
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 选择行为条件
    chooseCondition (val, data) {
      this.chooseDataList=[]
      data.checkedNodes.map(item => {
        if (item.a_base_robot_id) {
          this.chooseDataList.push(item)
        }
      })
    },
    // 编辑行为树
    editCondition () {
      this.chooseDataList.map(item => {
        // 机器人行为
        if (typeof (item.a_robot_condition) == 'string') {
          item.a_robot_condition = this.robotTypeBack(item.a_robot_condition)
        }
        this.conditionIndex=item.a_robot_condition.length-1
        // 延时时间
        if (typeof (item.a_robot_delay) == 'string') {
          item.a_robot_delay = this.robotTypeTime(item.a_robot_delay)
        }
        // 行为触发条件
        if (typeof (item.a_robot_trigger) == 'string') {
          item.a_robot_trigger = this.robotTypeTime(item.a_robot_trigger)
        } 
        this.behaviorIndex=item.a_robot_behavior.length-1
        // 机器人充值次数 
        if (typeof (item.recharge_num_rand) == 'string') {
          item.recharge_num_rand = this.robotTypeBack(item.recharge_num_rand)
        } 
        this.rechargeIndex=item.recharge_num_rand.length-1
        // 局内筹码不足机器人充值及金额 
        if (typeof (item.is_recharge_rand) == 'string') {
          item.is_recharge_rand = this.robotTypeBack(item.is_recharge_rand)
        } 
        this.rechargeRandIndex=item.is_recharge_rand.length-1
        // 机器人充值随机时间 
        if (typeof (item.recharge_time_rand) == 'string') {
          item.recharge_time_rand = this.robotTypeBack(item.recharge_time_rand)
        } 
        this.rechargeTimeIndex=item.recharge_time_rand.length-1
        // 机器人离开房间随机时间 
        if (typeof (item.exit_time_rand) == 'string') {
          item.exit_time_rand = this.robotTypeBack(item.exit_time_rand)
        } 
        this.exitTimeIndex=item.exit_time_rand.length-1
      })
      this.editShow = true
      this.$emit('onHideAddDetails')
    },
    // 行为
    actionType (cellValue) {
      if (cellValue) {
        return (this.ROBOT_BEHAVIOR.find((item) => item.value === cellValue)?.label || "-");
      } else {
        return '无操作'
      }
    },
    // 确认
    handleConfirm (formvalue) {
      let that = this, conditionData = [], noData = [],
        params = JSON.parse(JSON.stringify(that.chooseDataList[0]));
        
      if (that.isShow) {
        conditionData = JSON.parse(JSON.stringify(that.chooseDataList))
        conditionData.map(item => {
          item.a_robot_condition = this.robotTypeConBack(item.a_robot_condition)
          item.a_robot_delay = this.robotTypeConBack(item.a_robot_delay)
          item.a_robot_trigger = this.robotTypeConBack(item.a_robot_trigger)
          item.a_robot_behavior = JSON.stringify(item.a_robot_behavior)
        })
      } else {
        if(!params.a_base_robot_id){
          return that.$message.error('请选择机器人')
        }
        if (params.a_robot_delay[0] > params.a_robot_delay[1]) {
          return that.$message.error('请输入正确的延迟时间')
        }
        params.a_robot_delay = this.robotTypeConBack(params.a_robot_delay)
        // 机器人条件
        params.a_robot_condition.map(item => {
          if (item.type == 4) {
            if (item.min > item.max) {
              noData.push(item)
            }
          }
        })
        if (noData.length) {
          return that.$message.error('请输入正确的万分比')
        }
        params.a_robot_condition = this.robotTypeConBack(params.a_robot_condition)
        // 机器人行为
        if(!params.a_robot_behavior.length){
          return that.$message.error('请输入正确的机器人行为')
        }
        params.a_robot_behavior = JSON.stringify(params.a_robot_behavior)
        // 触发点
        params.a_robot_trigger = this.robotTypeConBack(params.a_robot_trigger)

        params.recharge_num_rand = this.robotTypeConBack(params.recharge_num_rand)
        params.is_recharge_rand = this.robotTypeConBack(params.is_recharge_rand)
        params.recharge_time_rand = this.robotTypeConBack(params.recharge_time_rand)
        params.exit_time_rand = this.robotTypeConBack(params.exit_time_rand)

        params.recharge_credit_rand = JSON.stringify(params.recharge_credit_rand)
      }
      that.$refs[formvalue].validate((valid) => {
        if (valid) {
          if (this.isShow) {
            // 批量修改
            editRobotCondition(conditionData).then(function (res) {
              that.$message.success(res.msg)
              that.handleClose()
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          } else {
            addRobotCondition(params).then(function (res) {
              that.$message.success(res.msg)
              that.handleClose()
              that.$emit('onHideDetails', true)
            }).catch((error) => {
              that.$message.error(error.msg)
            })
          }
        } else {
          return false;
        }
      });
    },
    // 新增行为
    addBehavior (index) {
      this.behaviorIndex++
      this.chooseDataList[index].a_robot_behavior.push({
        action: 1, pro: 1
      })
    },
    // 删除行为
    deleteBehavior (index,two) {
      this.behaviorIndex--
      this.chooseDataList[index].a_robot_behavior.splice(two, 1,)
    },
    // 新增条件
    addCondition (index) {
      this.conditionIndex++
      this.chooseDataList[index].a_robot_condition.push({
        type: 1, condition: 1
      })
    },
    // 删除条件
    deleteCondition (index,two) {
      this.conditionIndex--
      this.chooseDataList[index].a_robot_condition.splice(two, 1,)
    },
    // 新增充值次数
    addRecharge (index) {
      this.rechargeIndex++
      this.chooseDataList[index].recharge_num_rand.push({
        type: 1, condition: 1
      })
    },
    // 删除充值次数
    deleteRecharge (index,two) {
      this.rechargeIndex--
      this.chooseDataList[index].recharge_num_rand.splice(two, 1,)
    },
    // 新增局内筹码不足是否充值
    addRechargeRand (index) {
      this.rechargeRandIndex++
      this.chooseDataList[index].is_recharge_rand.push({
        type: 1, condition: 1
      })
    },
    // 删除局内筹码不足是否充值
    deleteRechargeRand (index,two) {
      this.rechargeRandIndex--
      this.chooseDataList[index].is_recharge_rand.splice(two, 1,)
    },
    // 新增局机器人充值随机时间
    addRechargeTime (index) {
      this.rechargeTimeIndex++
      this.chooseDataList[index].recharge_time_rand.push({
        type: 1, condition: 1
      })
    },
    // 删除机器人充值随机时间
    deleteRechargeTime (index,two) {
      this.rechargeTimeIndex--
      this.chooseDataList[index].recharge_time_rand.splice(two, 1,)
    },
    // 新增机器人离开房间随机时间
    addExitTime (index) {
      this.exitTimeIndex++
      this.chooseDataList[index].exit_time_rand.push({
        type: 1, condition: 1
      })
    },
    // 删除机器人离开房间随机时间
    deleteExitTime (index,two) {
      this.exitTimeIndex--
      this.chooseDataList[index].exit_time_rand.splice(two, 1,)
    },
    // 机器人条件配置-转数组
    robotTypeConBack (arr) {
      let reward = '';
      if (arr[0] && typeof (arr[0]) == 'string') {
        if (item[0] == 4) {
          reward += item.type + ',' + item.min + ',' + item.max + ';'
        } else {
          reward = item.type + ',' + item.condition + ';'
        }
      } else {
        // 多个
        if (this.editShow) {
          arr.map(item => {
            if (item.type == 4) {
              reward += item.type + ',' + item.min + ',' + item.max + ';'
            } else {
              reward += item.type + ',' + item.condition + ';'
            }
          })
        } else {
          arr.map(item => {
            if (item.type == 4) {
              reward += item.type + ',' + item.min + ',' + item.max + ';'
            } else {
              reward += item.type + ',' + item.condition + ';'
            }
          })
        }
      }
      reward = reward.substring(0, reward.length - 1)
      return reward
    },
    robotTypeActionBack (arr) {
      let reward = '';
      if (arr[0] && typeof (arr[0]) == 'string') {
        reward = item.action + ',' + item.pro + ';'
      } else {
        // 多个
        arr.map(item => {
          reward += item.action + ',' + item.pro + ';'
        })
      }
      reward = reward.substring(0, reward.length - 1)
      return reward
    },
    // 机器人时间配置
    robotTypeTime (str) {
      let arr = [];
      arr = [{ type: Number(str.split(',')[0]), condition: Number(str.split(',')[1]) }]
      return arr
    },
    robotTypeBack (str) {
      // 一组值
      let arr = this.$public.srtToArr(str), arrData = [];
      // 只有一个行为
      if (arr[0] && typeof (arr[0]) == 'string') {
        if (arr[0] == 4) {
          arrData.push({ type: Number(arr[0]), min: Number(arr[1]), max: Number(arr[2]) })
        } else {
          arrData.push({ type: Number(arr[0]), condition: Number(arr[1]) })
        }
      } else {
        // 多个行为
        arr.map(item => {
          if (item[0] == 4) {
            arrData.push({ type: Number(item[0]), min: Number(item[1]), max: Number(item[2]) })
          } else {
            arrData.push({ type: Number(item[0]), condition: Number(item[1]) })
          }
        })
      }
      return arrData
    },
    conditionClose () {
      this.editShow = false
      this.$emit('onHideAddDetails',false)
    },
    // 取消
    handleClose () {
      this.conditionDataList = []
      this.chooseDataList=[]
      this.conditionClose()
      this.$emit('onHideDetails', false)
    },
  }
}
</script>

<style scoped lang="scss">
.border-item {
  padding: 10px;
}
.box-title {
  font-size: 17px;
  font-weight: 600;
}
.btn-box-add {
  width: 50px;
  margin-top: -20px;
  margin-right: -15px;
  text-align: center;
  .el-button {
    height: 28px;
  }
}
.btn-box-delete {
  width: 50px;
  margin-bottom: 20px;
  text-align: center;
  .el-button {
    height: 28px;
  }
}
</style>
